<template>
  <ContainerGroup>
    <Container style="margin-bottom:10px;">
      <FilterForm
        ref="filterForm"
        :elements="filterElements"
        @submit="handleSearch"
        @reset="handlerReset"
      />
    </Container>
    <Container height="fill" display="flexY">
      <Table
        :columns="tableColumns"
        :loading="tableLoading"
        :data="tableData"
        :pagination="{
          total: total,
          current: currentPage,
          pageSize: pageSize,
        }"
        @paginationChange="pageChange"
      >
        <template #status="{ row }">{{ row.status===0?'待审核':row.status===1?'已通过': '已驳回' }}</template>
        <template #caozuo="{ row }">
          <Tooltip v-if="row.status!==1" content="审核" icon="check" @click="handleAprove(row)" />
        </template>
      </Table>
      <Dialog
        title="审核"
        :visible="dialogVisible"
        :footer-btns="[
          {
            text: '通过',
            type: 'primary',
            trigger: 'confirm',
            loading: tgLoading
          },
          {
            text: '驳回',
            type: 'delete',
            trigger: 'reject',
            loading: bhLoading
          }
        ]"
        @reject="handleReject"
        @confirm="handleConfirm"
        @cancel="dialogVisible=false"
      >
        <el-form ref="ruleForm" :model="ruleForm" label-width="80px" class="demo-ruleForm">
          <el-form-item label="处理意见" prop="comments">
            <div class="input-box">
              <el-input
                v-model.trim="ruleForm.comments"
                type="textarea"
                :rows="4"
                maxlength="50"
                placeholder="请输入处理意见"
              />
            </div>
          </el-form-item>
        </el-form>
      </Dialog>
    </Container>
  </ContainerGroup>
</template>
<script>
import {
  scshGetList,
  scshauditOperation
} from '@/apis/specialFunds/systermSetting'
export default {
  name: 'DeleteAudiManagement', // 删除审核管理
  data() {
    return {
      tgLoading: false,
      bhLoading: false,
      ruleForm: {
        comments: ''
      },
      rules: {
        comments: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ]
      },
      dialogVisible: false,
      filterElements: [
        {
          key: 'financialCode',
          type: 'input',
          label: '财务编码',
          value: ''
        },
        {
          key: 'projectCode',
          type: 'input',
          label: '项目编号',
          value: ''
        },
        {
          key: 'leaderName',
          type: 'input',
          label: '项目负责人',
          value: ''
        },
        {
          key: 'projectName',
          type: 'input',
          label: '综合搜索',
          placeholder: '项目简称/项目全称',
          value: '',
          width: 180
        },
        {
          key: 'status',
          type: 'Select',
          label: '状态',
          value: '',
          width: 210,
          options: [
            {
              label: '待审核',
              value: '0'
            },
            {
              label: '已通过',
              value: 1
            },
            {
              label: '已驳回',
              value: 2
            }
          ],
          filterable: true,
          clearable: true
        }
      ],
      tableColumns: [
        {
          title: '财务编码',
          dataIndex: 'financialCode'
        },
        {
          title: '项目编号',
          dataIndex: 'projectCode'
        },
        {
          title: '项目类别',
          dataIndex: 'entryName'
        },
        {
          title: '项目简称',
          dataIndex: 'financialName'
        },
        {
          title: '项目全称',
          dataIndex: 'projectInfo'
        },
        {
          title: '项目负责人',
          dataIndex: 'userName'
        },
        {
          title: '申请人',
          dataIndex: 'applyPerson'
        },
        {
          title: '申请人科室',
          dataIndex: 'applyDeptName'
        },
        {
          title: '状态',
          dataIndex: 'status',
          type: 'otherTag'
        },
        {
          title: '操作时间',
          width: 160,
          type: 'otherTag',
          dataIndex: 'caozuo'
        }
      ],
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableLoading: false,
      tableData: [],
      newCondition: {},
      currentRow: null
    }
  },
  created() {},
  methods: {
    handleReject() {
      // 驳回
      if (!this.ruleForm.comments) {
        this.$message.warning('请输入处理意见')
        return
      }
      this.bhLoading = true
      this.apiCommon(2)
    },
    handleConfirm() {
      // 通过
      this.tgLoading = true
      this.apiCommon(1)
    },
    apiCommon(status) {
      const param = {
        comments: this.ruleForm.comments,
        financialCode: this.currentRow.financialCode,
        status: status
      }
      scshauditOperation(param).then(res => {
        this.tgLoading = false
        this.bhLoading = false
        this.dialogVisible = false
        if (res.data.code === 200) {
          this.getData()
          this.$message.success(res.data.message)
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    handleAprove(row) {
      this.currentRow = row
      this.ruleForm.comments = ''
      this.dialogVisible = true
    },
    handleSearch(value) {
      this.newCondition = value
      this.currentPage = 1
      this.getData()
    },
    getData() {
      const params = {
        financialCode: this.newCondition?.financialCode,
        projectCode: this.newCondition?.projectCode,
        leaderName: this.newCondition?.leaderName,
        projectName: this.newCondition?.projectName,
        status: Number(this.newCondition?.status),
        pageNum: this.currentPage,
        pageSize: this.pageSize
      }
      this.tableLoading = true
      scshGetList(params)
        .then(res => {
          this.tableLoading = false
          if (res.data.code === 200) {
            this.tableData = res.data.data.list
            const { userName, deptName } = this.tableData[0]
            this.projectLeader = userName
            this.deptName = deptName
            this.total = res.data.data.total
          } else {
            this.$message.error(res.data.message)
          }
        })
        .catch(() => {
          this.tableLoading = false
        })
    },
    handlerReset(val) {
      this.handleSearch()
    },
    pageChange(payload) {
      this.currentPage = payload.current
      this.pageSize = payload.pageSize
      this.getData()
    }
  }
}
</script>
<style lang="less" scoped>
.demo-ruleForm {
  height: 140px;
  width: 350px;
}
.input-box {
  // border: 1px solid red;
}
.input-warning {
  font-size: 12px;
  color: #f50909;
}
</style>
